#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/1/9 18:57
# ===========================================
#       题目名称： 1.两数之和
#       题目地址： https://leetcode.cn/problems/two-sum/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution(object):
    def twoSum(self, nums, target):
        d = {}  # k :target - nums[i] , v : i
        for i in range(len(nums)):
            source = d.get(nums[i])
            if source is None:
                d[target - nums[i]] = i
            else:
                if nums[i] in d.keys():
                    return [source, i]


if __name__ == '__main__':
    s = Solution()
    print('[2, 7, 11, 15], 9 =>' + s.twoSum([2, 7, 11, 15], 9).__str__())
    print('[3,2,4], 6 =>' + s.twoSum([3, 2, 4], 6).__str__())
    print('[3,3], 6 =>' + s.twoSum([3, 3], 6).__str__())
